﻿Imports Microsoft.AspNet.Membership.OpenAuth
Imports System.Data.OleDb

Public Class Register
    Inherits Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        RegisterUser.ContinueDestinationPageUrl = Request.QueryString("ReturnUrl")
    End Sub

    Protected Sub RegisterUser_CreatedUser(ByVal sender As Object, ByVal e As EventArgs) Handles RegisterUser.CreatedUser
        FormsAuthentication.SetAuthCookie(RegisterUser.UserName, createPersistentCookie:=False)

        Dim continueUrl As String = RegisterUser.ContinueDestinationPageUrl
        If Not OpenAuth.IsLocalUrl(continueUrl) Then
            continueUrl = "~/"
        End If

        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("ClubsConnectionString").ConnectionString)
        Dim createUserSQL As String = "INSERT INTO UserProfile(Username,CountryID_FK,EmailAddress,FavouriteClub_FK,CreatedAt) VALUES (@f1,@f2,@f3,@f4,@f5)"
        Dim createUserCmd As OleDbCommand = New OleDbCommand(createUserSQL, oleDbConn)
        oleDbConn.Open()
        createUserCmd.CommandType = CommandType.Text
        createUserCmd.Parameters.AddWithValue("@f1", RegisterUser.UserName)
        createUserCmd.Parameters.AddWithValue("@f2", 1)
        createUserCmd.Parameters.AddWithValue("@f3", RegisterUser.Email)
        createUserCmd.Parameters.AddWithValue("@f4", 1)
        createUserCmd.Parameters.AddWithValue("@f5", DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"))
        createUserCmd.ExecuteNonQuery()

        System.Threading.Thread.Sleep(500)
        Response.Redirect("~/EditProfile.aspx")

        'Response.Redirect(continueUrl)

        createUserCmd.Dispose()
        oleDbConn.Close()
        oleDbConn.Dispose()
    End Sub
End Class